﻿$(document).ready(function () {

    ComFunJS.initForm();
    //初始化树
    $.ajax({
        type: "GET",
        url: "../Base/AdminHandle.ashx",
        dataType: "html",
        data: { "CheckNodes": $("#hidConfirmUsers").val(), "Action": "GetBranchUser" },
        success: function (msg) {
            var zNodes = null;
            var zTreeObj = null;
            var setting = {
                data: {
                    simpleData: {
                        enable: true,
                        idKey: "id",
                        pIdKey: "pId",
                        rootPId: 0
                    }
                },
                check: {
                    enable: true,
                    chkStyle: "checkbox",
                    chkboxType: { "Y": "ps", "N": "s" }
                },
                view: {
                    showLine: false
                },
                callback: {
                    onCheck: function (event, treeId, treeNode) {
                        var checknodes = zTreeObj.getCheckedNodes(true);
                        var s = "";
                        if (checknodes.length != 0) {
                            $.each(checknodes, function (i, n) {
                                var check = (n && n.isUser == "Y");
                                if (check) {
                                    s = s + n.id + ',';
                                }
                            });
                            $("#hidConfirmUsers").val(s);
                            $(".labcount").text(s.split(',').length)
                        }
                        else {
                            return false;
                        }
                    }
                }
            };
            zNodes = eval(msg);
            zTreeObj = $.fn.zTree.init($("#tree"), setting, zNodes);
        }
    });
    $(".labcount").text($("#hidConfirmUsers").val().split(',').length - 1)

});
function CheckData() {
    if (typeof (getdata) === "function") {
        getdata();
    }
    if (confirm('你确定要保存吗？')) {
        return true;
    }
    else {
        return false;
    }
}

function getflowdata(FormCode, intPID) {
    //流程处理
    $.getJSON(ComFunJS.getRootPath() + "/Comon/ComBaseAPI.ashx", { Action: "GetFlowJsonData", FormCode: FormCode, intPID: intPID }, function (data) {

        var strTaskName, strFlowRoleName, strFlowTaskUser, strTaskEndTime, strTaskUserView = "";
        for (var i = 0; i < data.length; i++) {
            var users = data[i].TaskUser.split(',');
            for (var j = 0; j < users.length; j++) {
                strTaskName = strTaskName + "<td  style='text-align:center'>" + data[i].TaskName + "</td>";
                strFlowRoleName = strFlowRoleName + "<td  style='text-align:center'>" + data[i].RoleName + "</td>";
                strFlowTaskUser = strFlowTaskUser + "<td  style='text-align:center'>" + data[i].TaskUser + "</td>";
                strTaskEndTime = strTaskEndTime + "<td  style='text-align:center'>" + data[i].TaskEndTime + "</td>";
                strTaskUserView = strTaskUserView + "<td  style='text-align:center'>" + data[i].TaskUserView + "</td>";
            }
        }
        $("#flowbody tr").eq(0).empty().append("<td style='text-align:center'>工作</td>" + strTaskName);
        $("#flowbody tr").eq(1).empty().append("<td  style='text-align:center'>人员</td>" + strFlowRoleName);
        $("#flowbody tr").eq(2).empty().append("<td  style='text-align:center'>签署</td>" + strFlowTaskUser);
        $("#flowbody tr").eq(3).empty().append("<td  style='text-align:center'>日期</td>" + strTaskEndTime);
        $("#flowbody tr").eq(4).empty().append("<td  style='text-align:center'>意见</td>" + strTaskUserView);



        //合并流程数据
        var titletr = $("#flowbody tr").eq(0);
        var trlen = $("td", titletr).length;
        $("#TabFlow thead tr th").attr("colspan", trlen);
        for (var i = 1; i < trlen; i++) {
            if (titletr.find("td").eq(i).text() === titletr.find("td").eq(i - 1).text()) {
                titletr.find("td").eq(i).attr("colspan", (titletr.find("td").eq(i - 1).attr("colspan") || 1) * 1 + 1);
                titletr.find("td").eq(i - 1).addClass("removetd");
            }
        }
        $(".removetd").remove();
        $("#TabFlow").show();
        //合并流程数据
    })
}


